﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DemoMenu_01.Models.Interface;
using DemoMenu_01.Models.Exec;
using System.Web.Security;
using System.Resources;
using System.Reflection;
using DemoMenu_01.Models.Language;
using DemoMenu_01.Models.Service;

namespace DemoMenu_01.Controllers
{
    public class UserController : ControllerExtent
    {
        //
        // GET: /User/

        IAccount _Account;

        private IAccount Account
        {
            get
            {
                if (_Account == null)
                {
                    _Account = new ExecAccount();
                    return _Account;
                }
                else
                {
                    return _Account;
                }

            }
        }


        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult LoginAction(string UserName, string PassWord)
        {

            if (UserName.ToLower() == "admin" && PassWord == "123")
            {
                Dictionary<string, string> userlogin = new Dictionary<string, string>();
                userlogin.Add(Guid.NewGuid().ToString(), "Mr Admin");
                Session["Userlogin"] = userlogin;
                Session["UserType"] = "admin";
            }
            else
            {
                return Content(string.Empty);
            }
            return PartialView("UC_LoginLink");
        }
        [HttpPost]
        public ActionResult LogoutAction()
        {
            Session["Userlogin"] = null;
            Session["UserType"] = "normal";
            return PartialView("UC_LoginLink");
        }
        [HttpPost]

        public ActionResult RegisterAction(string UserName, string PassWord)
        {

            MembershipCreateStatus Result = Account.Register(UserName, PassWord);

            if (Result == MembershipCreateStatus.Success)
            {
                return Json(new { result_bool = true, result_Str = PartialView("UC_LoginLink") }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                string Result_Str = resourceManager.GetString(Result.ToString());              
                return Json(new { result_bool = false , result_Str =  Result_Str}, JsonRequestBehavior.AllowGet);

                //return Content(string.Empty);
            }

        }
        [HttpPost]
        public ActionResult RegisterCode()
        {
            DateTime now1 = DateTime.Now;

            while (DateTime.Now < now1.AddSeconds(0.01))
            {

            }

            #region selectList Carrier
            List<Carrier> lstCarrier = new List<Carrier>();
            Carrier carrier0 = new Carrier();

            Carrier carrier1 = new Carrier()
            {
                CarrierID = Guid.NewGuid(),
                CarrierName = "AT&T"
            };
            Carrier carrier2 = new Carrier()
            {
                CarrierID = Guid.NewGuid(),
                CarrierName = "Sprint"
            };
            Carrier carrier3 = new Carrier()
            {
                CarrierID = Guid.NewGuid(),
                CarrierName = "Verizone"
            };
            lstCarrier.Add(carrier0);
            lstCarrier.Add(carrier1);
            lstCarrier.Add(carrier2);
            lstCarrier.Add(carrier3);


            SelectList selectListCarrier = new SelectList(lstCarrier, "CarrierID", "CarrierName");
            ViewData["lstCarrier"] = selectListCarrier;
            #endregion

            #region selectList Brand
            List<Brand> lstBrand = new List<Brand>();
            Brand Brand0 = new Brand();

            Brand Brand1 = new Brand()
            {
                BrandID = Guid.NewGuid(),
                BrandName = "Iphone"
            };
            Brand Brand2 = new Brand()
            {
                BrandID = Guid.NewGuid(),
                BrandName = "LG"
            };
            Brand Brand3 = new Brand()
            {
                BrandID = Guid.NewGuid(),
                BrandName = "HTC"
            };
            Brand Brand4 = new Brand()
            {
                BrandID = Guid.NewGuid(),
                BrandName = "Samsung"
            };
            lstBrand.Add(Brand0);
            lstBrand.Add(Brand1);
            lstBrand.Add(Brand2);
            lstBrand.Add(Brand3);
            lstBrand.Add(Brand4);



            SelectList selectListBrand = new SelectList(lstBrand, "BrandID", "BrandName");
            ViewData["lstBrand"] = selectListBrand;
            #endregion

            #region selectList Model
            List<Model> lstModel = new List<Model>();
            Model Model0 = new Model();

            Model Model1 = new Model()
            {
                ModelID = Guid.NewGuid(),
                ModelName = "Iphone 3G"
            };
            Model Model2 = new Model()
            {
                ModelID = Guid.NewGuid(),
                ModelName = "Iphone 4s"
            };
            Model Model3 = new Model()
            {
                ModelID = Guid.NewGuid(),
                ModelName = "Galaxy S4"
            };
            lstModel.Add(Model0);
            lstModel.Add(Model1);
            lstModel.Add(Model2);
            lstModel.Add(Model3);


            SelectList selectListModel = new SelectList(lstModel, "ModelID", "ModelName");
            ViewData["lstModel"] = selectListModel;
            #endregion



            return PartialView("UC_RegisterCode");
        }

    }
    public class Carrier
    {
        private Guid _CarrierID;
        public Guid CarrierID
        {
            get { return _CarrierID; }
            set { _CarrierID = value; }
        }
        private string _CarrierName;
        public string CarrierName
        {
            get { return _CarrierName; }
            set { _CarrierName = value; }
        }
    }
    public class Brand
    {
        private Guid _BrandID;
        public Guid BrandID
        {
            get { return _BrandID; }
            set { _BrandID = value; }
        }
        private string _BrandName;
        public string BrandName
        {
            get { return _BrandName; }
            set { _BrandName = value; }
        }
    }
    public class Model
    {
        private Guid _ModelID;
        public Guid ModelID
        {
            get { return _ModelID; }
            set { _ModelID = value; }
        }
        private string _ModelName;
        public string ModelName
        {
            get { return _ModelName; }
            set { _ModelName = value; }
        }
    }
}


